<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryRef"
      :inline="true"
    >
      <el-form-item label="会员id" prop="memId">
        <el-input
              v-model="queryParams.memId"
              placeholder="请输入会员id"
              clearable
              style="width: 200px"

           />
        </el-form-item>
      <el-form-item>
        <el-form-item label="类型" prop="typeId">
           <el-select v-model="queryParams.typeId" placeholder="类型" clearable style="width: 200px">
              <el-option
                 v-for="dict in typesOptions"
                 :key="dict.value"
                 :label="dict.label"
                 :value="dict.value"
              />
           </el-select>
        </el-form-item>
        <el-form-item label="日志类别" prop="checkType">
           <el-select v-model="queryParams.checkType" placeholder="日志类别" clearable style="width: 200px">
              <el-option
                 v-for="dict in typesList"
                 :key="dict.value"
                 :label="dict.label"
                 :value="dict.value"
              />
           </el-select>
        </el-form-item>
        <el-button type="primary" icon="Search" @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>



    <el-table
      v-loading="loading"
      :data="orderList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column
        label="变动id"
        width="80"
        prop="id"
        :show-overflow-tooltip="true"
        align="center"
      />
      
      <el-table-column
        label="会员id"
        width="80"
        prop="memId"
        :show-overflow-tooltip="true"
        align="center"
      />

      <el-table-column
        label="变动类型"
        align="center"
        prop=""
        width="100"
      >
        <template #default="scope">
          <span>{{ scope.row.typeId == 1?'增加':'消费' }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="数额(元)"
        width="100"
        prop="value"
        :show-overflow-tooltip="true"
        align="center"
      />
      <el-table-column
        label="变动前(元)"
        width="150"
        prop="before"
        :show-overflow-tooltip="true"
        align="center"
      />
      <el-table-column
        label="变动后(元)"
        width="150"
        prop="after"
        :show-overflow-tooltip="true"
        align="center"
      />
      <el-table-column
        label="变动时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>

      <el-table-column
        label="备注"

        prop="memo"
        align="center"
        :show-overflow-tooltip="true"
      />






    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      v-model:page="queryParams.pageNum"
      v-model:limit="queryParams.pageSize"
      @pagination="getList"
    />


      <!-- <template #footer v-if="detailObject.orderStatus == 4">
        <div class="dialog-footer">
          <el-button type="primary" @click="handleUpdate">发 货</el-button>

        </div>
      </template> -->

  </div>
</template>

<script setup name="changeLog">
import { getLogList,getLogDetail } from "@/api/changeLog/index";
import { onMounted } from "vue";
const { proxy } = getCurrentInstance();
//引入useRoute
import { useRoute } from 'vue-router';
//获取传参
const route = useRoute();
let memId = route.query.memId;



const orderList = ref([]);
const skuList = ref([]);
const open = ref(false);
const loading = ref(true);
const memloading = ref(false);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const title = ref("发货");
const detailTitle = ref("订单详情");
const detailOpen = ref(false);
const memberOptions = ref([]);
const typesOptions = ref([
  {
    label:'增加',
    value:1
  },
  {
    label:'消费',
    value:2
  }
])
const typesList = ref([
  {
    label:'会员余额变动',
    value:1
  },
  {
    label:'会员饭团变动 ',
    value:2
  },
  {
    label:'会员饭券变动',
    value:3
  },
  {
    label:'会员饭点变动',
    value:4
  },
  {
    label:'会员广告积分变动',
    value:5
  },
  {
    label:'会员奖金池变动',
    value:6
  }
])

const data = reactive({
  form: {},
  detailObject: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    memId: undefined,
    typeId: undefined,
    checkType: 1,
  },
  rules: {
    expressName: [
      { required: true, message: "物流公司不能为空", trigger: "blur" },
    ],
    expressId: [
      { required: true, message: "物流单号不能为空", trigger: "blur" },
    ],
  },
});

const { queryParams, form, rules, detailObject } = toRefs(data);

/** 查询订单列表 */
function getList() {
  loading.value = true;
  getLogList(queryParams.value).then((response) => {
    orderList.value = response.rows;
    total.value = response.total;
    loading.value = false;
  });
}

onMounted(()=>{

  if(memId){

    queryParams.value.memId = memId

  }
  getList();
})






/** 取消按钮 */
function cancel() {
  open.value = false;
  reset();
}
/** 表单重置 */
function reset() {
  form.value = {
    id: undefined,
    expressId: undefined,
    expressName: undefined,
  };
  proxy.resetForm("orderRef");
}
/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1;
  getList();
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef");
  handleQuery();
}
/** 多选框选中数据 */
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.postId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
}

/** 查看订单详情 */
function handleView(row){
  getLogDetail({id:row.id}).then((response) => {
    detailObject.value = response.data
    detailOpen.value = true
  });

}


/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    "system/post/export",
    {
      ...queryParams.value,
    },
    `post_${new Date().getTime()}.xlsx`
  );
}


</script>
<style lang="scss" scoped>


</style>
